package com.bw.msg.mvvm.viewmodel;

import com.bw.msg.mvvm.adpter.MessageAdapter;
import com.bw.msg.mvvm.model.MessageModel;
import com.bw.msg.mvvm.model.entity.MessageEntity;
import com.bw.mvvm_comom.entity.BaseEntity;
import com.bw.mvvm_comom.mvvm.BaseViewModel;

import java.util.HashMap;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class MessageViewModel extends BaseViewModel<MessageModel> {

    public MessageAdapter messageAdapter = new MessageAdapter();
    @Override
    public void onCreate() {
        super.onCreate();
        HashMap<String,Object> map = new HashMap<>();
        map.put("id",10);

        m.requestMessageModel(map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(this);

    }

    @Override
    protected void result(BaseEntity baseEntity) {
        if (baseEntity instanceof MessageEntity){
            MessageEntity messageEntity = (MessageEntity) baseEntity;
            messageAdapter.setNewInstance(messageEntity.data);
        }
    }
}
